﻿using System.Diagnostics;
using System.Drawing.Text;
using System.IO;
using ResxHelper.Logic.Actions;
using ResxHelper.Logic.Readers;
using System;
using System.Collections.Generic;
using System.Linq;
using ResxHelper.Object;
using Ionic.Zip;

namespace ResxHelper.Logic
{
    // TODO refactor this into something more useful
    public class Core
    {
        /// <summary>
        /// Return a dictionary containing information about files that are missing keys contained in the invariant file.
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static Dictionary<string, string[]> GetMissingKeysFromInvariant(string filePath)
        {
            var invariantPath = ResourceFile.GetInvariantFilePath(filePath);
            var resourceFile = ResourceFileReaderFactory.GetReader(invariantPath, ResourceType.Resx).Read();
            if (resourceFile == null) return new Dictionary<string, string[]>();

            var files = ResourceFile.GetAllResourceFiles(filePath, false);

            var dict = new Dictionary<string, string[]>();
            foreach (var file in files)
            {
                var lang = file.CultureInfo.Name;
                var missingWords =
                    (from key in resourceFile.Entries
                     where !file.Entries.ContainsKey(key.Key)
                     select key.Key).ToArray();
                if(missingWords.Any()) dict.Add(lang, missingWords);
            }

            return dict;
        }

        /// <summary>
        /// Return a dictionary containing information about files that are missing values for keys they have
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static Dictionary<string, string[]> GetMissingKeyValuesFromInvariant(string filePath)
        {
            throw new NotImplementedException();
        }

        public enum ZipResourceContent
        {
            DotNet,
            Android,
            iOS
        }
    }
}
